package com.vanke.devops.domain.manager.docker.extend.exec;

import com.github.dockerjava.core.DockerClientConfig;
import com.github.dockerjava.jaxrs.AbstrSyncDockerCmdExec;
import com.github.dockerjava.netty.MediaType;
import com.vanke.devops.domain.manager.docker.extend.command.InspectServiceCmd;
import com.vanke.devops.domain.manager.docker.extend.model.Service;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.GenericType;

/**
 * @author 陈景阳
 * @since 2018/6/8
 */
public class InspectServiceCmdExec extends AbstrSyncDockerCmdExec<InspectServiceCmd,Service> implements InspectServiceCmd.Exec {


    private static final Logger LOGGER = LoggerFactory.getLogger(InspectServiceCmdExec.class);

    public InspectServiceCmdExec(WebTarget baseResource, DockerClientConfig dockerClientConfig) {
        super(baseResource, dockerClientConfig);
    }

    @Override
    protected Service execute(InspectServiceCmd command) {

        WebTarget webResource = getBaseResource().path("/services/{id}").resolveTemplate("id",
                command.getServiceId());

        LOGGER.debug("GET: {}", webResource);

        return webResource.request().accept(javax.ws.rs.core.MediaType.APPLICATION_JSON)
                .get(new GenericType<Service>() {
                });
    }
}
